import { useMemo } from 'react'

import { getFirstLineName, getTailLineName } from '../../utils'
import { TCol } from './interface'

export const useCommonCols = (hasFilter?: boolean) => {
  return useMemo(
    () => [
      {
        field: 'channelName',
        headerName: '渠道名称',
        flex: 2,
        filter: hasFilter,
        suppressHeaderFilterButton: true,
      } satisfies TCol<'channelName'>,
      {
        field: 'channelNo',
        headerName: '渠道代码',
      } satisfies TCol<'channelNo'>,
      {
        field: 'merchantServers',
        headerName: '服务商',
      } satisfies TCol<'merchantServers'>,
      {
        field: 'channelInnerName',
        headerName: '内置名',
      } satisfies TCol<'channelInnerName'>,
      {
        field: 'destinationCountry',
        headerName: '目的国',
      } satisfies TCol<'destinationCountry'>,
      {
        field: 'firstLine',
        headerName: '头程运输方式',
        minWidth: 142,
        filter: hasFilter,
        suppressHeaderFilterButton: true,
        valueFormatter: ({ value }) => getFirstLineName(value) || '',
      } satisfies TCol<'firstLine'>,
      {
        field: 'tailLine',
        headerName: '尾程运输方式',
        minWidth: 142,
        valueFormatter: ({ value }) => getTailLineName(value) || '',
      } satisfies TCol<'tailLine'>,
    ],
    [hasFilter],
  )
}
